package com.designpatterns.compund.compund1;

public class DuckSimulator {
    public static void main(String[] args) {
        DuckSimulator simulator = new DuckSimulator();
        AbstractDuckFactory abstractDuckFactory = new CountingDuckFactory();
        simulator.simulate(abstractDuckFactory);
    }

    void simulate(AbstractDuckFactory abstractDuckFactory) {
        Quackable redHeadDuck = abstractDuckFactory.createRedHeadDuck();
        Quackable duckCall = abstractDuckFactory.createDuckCall();
        Quackable rubberDuck = abstractDuckFactory.createRubberDuck();
        Quackable gooseDuck = new GooseAdapter(new Goose());
        System.out.println("\nDuck Simulator: With Composite - Flocks");

        Flock flockDucks = new Flock();
        flockDucks.add(redHeadDuck);
        flockDucks.add(duckCall);
        flockDucks.add(rubberDuck);
        flockDucks.add(gooseDuck);

        Flock flockOfMallards = new Flock();
        Quackable mallardOne = abstractDuckFactory.createMallardDuck();
        Quackable mallardTwo = abstractDuckFactory.createMallardDuck();
        Quackable mallardThree = abstractDuckFactory.createMallardDuck();
        Quackable mallardFour = abstractDuckFactory.createMallardDuck();

        flockOfMallards.add(mallardOne);
        flockOfMallards.add(mallardTwo);
        flockOfMallards.add(mallardThree);
        flockOfMallards.add(mallardFour);

        flockDucks.add(flockOfMallards);

        System.out.println("\nDuck Simulator: with Observer");
        Quackologist quackologist = new Quackologist();
        flockDucks.registerObserver(quackologist);

        simulate(flockDucks);

        //System.out.println("\nDuck Simulator: mallard Flock Simulation");
        //simulate(flockOfMallards);

        System.out.println("\nThe ducks quacked " + QuackCounter.getNumberOfQuack() + " times");
    }

    void simulate(Quackable duck) {
        duck.quack();
    }
}
